import 'package:flutter/material.dart';
import '../model/health_record.dart';

class SelectRecordTypeDialog extends StatelessWidget {
  final String babyId;
  final Function(RecordType) onTypeSelected;

  const SelectRecordTypeDialog({
    Key? key,
    required this.babyId,
    required this.onTypeSelected,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return AlertDialog(
      title: const Text('选择记录类型'),
      content: SizedBox(
        width: double.maxFinite,
        child: GridView.count(
          crossAxisCount: 2,
          shrinkWrap: true,
          mainAxisSpacing: 8,
          crossAxisSpacing: 8,
          childAspectRatio: 2,
          children:
              RecordType.values
                  .where(
                    (type) => type != RecordType.custom,
                  ) // Put custom at the end
                  .followedBy([RecordType.custom])
                  .map((type) => _buildTypeItem(context, type))
                  .toList(),
        ),
      ),
    );
  }

  Widget _buildTypeItem(BuildContext context, RecordType type) {
    return Material(
      color: Colors.transparent,
      child: InkWell(
        onTap: () => onTypeSelected(type),
        borderRadius: BorderRadius.circular(8),
        child: Container(
          padding: const EdgeInsets.all(8),
          decoration: BoxDecoration(
            border: Border.all(color: type.color.withOpacity(0.2)),
            borderRadius: BorderRadius.circular(8),
          ),
          child: Row(
            children: [
              Container(
                padding: const EdgeInsets.all(8),
                decoration: BoxDecoration(
                  color: type.color.withOpacity(0.1),
                  shape: BoxShape.circle,
                ),
                child: Icon(type.icon, color: type.color, size: 20),
              ),
              const SizedBox(width: 8),
              Expanded(
                child: Text(
                  type.label,
                  style: TextStyle(
                    color: type.color,
                    fontWeight: FontWeight.w500,
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
